home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 989 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.6 KB

  1. Path: news4.noc.netcom.net!zdc!zippo!usenet
  2. Newsgroups: comp.lang.c
  3. Subject: Re: HELP! File Pointers
  4. Message-ID: <DKyzDM.FJ5@news.zippo.com>
  5. From: Jim McFarland <jgm6@orkand.em.cdc.gov>
  6. Date: Wed, 10 Jan 1996 14:39:21 GMT
  7. Sender: usenet@news.zippo.com
  8. References: <4csr4c$fem@newsbf02.news.aol.com>
  9. Organization: The Orkand Corporation
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. Nntp-Posting-Host: 158.111.166.77
  13. X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
  14. Mime-Version: 1.0
  15.  
  16. roberino@aol.com (Roberino) wrote:
  17. >I am currently trying to keep one file open while opening other
  18. >files one at a time using a separate file pointer.  However, as
  19. >soon as I read a line from the second file, the first file pointer
  20. >somehow gets destroyed and set to some position in the newly
  21. >opened file.  Has anyone else encountered this?  And if so,
  22. >is there a solution? (i.e. A way to protect the first file pointer
  23. >from being overwritten.)
  24. >
  25. >Here are the steps I am performing:
  26. >
  27. >void main()
  28. >{
  29. >    FILE *File1;
  30. >    FILE *File2;
  31. >
  32. >    File1 =   fopen("FILENAME", "r+");
  33. >    
  34. >    /* loop through lines in File1 using fgets() */
  35. >
  36. >    if (Condition) /* just indicating some condition was met */
  37. >    {
  38. >        File2 = fopen("FILENAME2", "r+");
  39. >      
  40. >        fgets(Line, File2); <----- As soon as this occurs, File1 gets
  41. >
  42. >    }
  43. >}
  44.  
  45. Well, what is Line?  You have not shown where Line is declared.  It could 
  46. be that Line is a pointer and memory is not allocated or it is too small 
  47. and the fgets() overwrites File1 because of this.  If you want help, 
  48. don't condense your code so much.  Due to the missing code, I am guessing 
  49. as to what the problem is...
  50.  
  51.